#ifndef DEPTHDATAPROCESSOR_H
#define DEPTHDATAPROCESSOR_H
class PointCloudGenerator;
#include <QObject>
#include <opencv2/opencv.hpp>
#include <pcl/point_cloud.h>
#include <pcl/visualization/pcl_visualizer.h>   


class DepthDataProcessor : public QObject
{
    Q_OBJECT
public:
    explicit DepthDataProcessor(QObject* parent = nullptr);

    void processDepthFrame(QSharedPointer<QByteArray> data);


    //const QVector<quint16>& getDepthData() const;
signals:
    //void pointCloudReady(const std::shared_ptr<pcl::PointCloud<pcl::PointXYZ>>& cloud);

    // 处理完成信号，传递结果
    //void depthImageReady(QSharedPointer<QImage> image);
    void depthImageReady(const QImage &image,const QVector<quint16>& depthData,int width,int height);
    void processingError(const QString& error);
private:
    //QHash<QString, QVariant> parseYaml(const QString& filePath);

    QByteArray mRevBuf;

    // 转换十六进制字符串为OpenCV Mat
    cv::Mat hexStringToDepthMat(const QString& hexString, int width, int height);
    // 解析uint16深度数据为QImage
    void parseDepthDataUint16(const QByteArray& data, QImage& image, int width, int height);

    PointCloudGenerator* generator; // 点云生成器
    // 解析十六进制字符串为十进制
    quint32 convertHexStringToDecimal(const QString& hexStr);
    QByteArray hexStringToLittleEndian(const QString& hexString);

    void processCompleteFrame(QByteArray& data);

    QString convertHexMsecToDateTime(const QString& hexMsec);

    QVector<quint16> m_irData; // 新增：存储原始深度数据（uint16）
    int m_frameCounter = 0; // 帧计数器
    const int FRAME_COUNTER_MAX = 10000; // 计数器阈值
    QVector<quint16> hexStringToDepthArray(const QString& hexString, int width, int height);
};

#define DepthDataProcessorRelease Singleton<DepthDataProcessor>::Release()
#define DepthDataProcessorInstance Singleton<DepthDataProcessor>::GetInstance()

#endif // DEPTHDATAPROCESSOR_H
